package com.zabra.zl.ui.index_fragment.account.presenter;

import com.zabra.zl.base.BasePresenter;
import com.zabra.zl.data.AccountBean;
import com.zabra.zl.ui.index_fragment.account.contract.AccountFragmentContract;
import com.zabra.zl.ui.index_fragment.account.model.AccountFragmentModel;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class AccountFragmentPresenter extends BasePresenter<AccountFragmentContract.View> implements AccountFragmentContract.Presenter {
    private AccountFragmentContract.Model model;
    public AccountFragmentPresenter() {
        model=new AccountFragmentModel();
    }

    @Override
    public void getData(RequestBody body) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.getData(body).enqueue(new Callback<AccountBean>() {
            @Override
            public void onResponse(Call<AccountBean> call, Response<AccountBean> response) {
                mView.hideLoading();
                mView.onSuccess(response.body(),response.headers().get("token"));
            }

            @Override
            public void onFailure(Call<AccountBean> call, Throwable t) {
                mView.hideLoading();
                mView.onError(t);
            }
        });
    }
}
